/*
 * @Author: yuki
 * @Date: 2025-10-25 23:01:03
 * @LastEditTime: 2025-10-26 15:38:39
 * @Description: 加密服务
 */
import { Injectable } from '@nestjs/common';
import * as bcrypt from 'bcrypt';

@Injectable()
export class BcryptService {
  // 加密密码（生成哈希）
  async hashPassword(plainPassword: string): Promise<string> {
    const salt = await bcrypt.genSalt(10);
    return bcrypt.hash(plainPassword, salt);
  }

  // 验证密码（比较明文与哈希是否匹配）
  async verifyPassword(
    plainPassword: string,
    hashedPassword: string
  ): Promise<boolean> {
    return bcrypt.compare(plainPassword, hashedPassword);
  }
}
